﻿$(function () {
  $("#album").tabs({

    select: function (event, ui) {
      $('#CurrentSelectedPage').val(ui.index);
    },

    panelTemplate: '<div class="albumPages"></div>',
    idPrefix: 'tabs-',
    ajaxOptions: {
      error: function (xhr, status, index, anchor) {
        $(anchor.hash).html(
						"Couldn't load this tab. We'll try to fix this as soon as possible. ");
      }
    }
  });
});

$(function () {
  $("#collection").tabs({
  });
});

function addStampToAlbum(albumId, stampId, pageNumber) {

  $.ajax(
			{
			  type: 'POST',
			  url: '/MyAlbums/AddStampToAlbum',
			  data: { albumId: albumId, stampId: stampId, pageNumber: pageNumber },
			  dataType: "json",

				success: function (data, response) {
			   

			  }
			});

};

function removeStampFromAlbum(albumId, stampId) {

  $.ajax(
			{
			  type: 'POST',
			  url: '/MyAlbums/RemoveStampFromAlbum',
			  data: { albumId: albumId, stampId: stampId },
			  dataType: "json",

			  success: function (data, response) {


			  }
			});

	};


//$(function () {
//	$("#tabs").tabs({

//		select: function (event, ui) {
//			$('#CurrentSelectedPage').val(ui.index);
//		},

//		ajaxOptions: {
//			error: function (xhr, status, index, anchor) {
//				$(anchor.hash).html(
//						"Couldn't load this tab. We'll try to fix this as soon as possible. " +
//						"If this wouldn't be a demo.");
//			}
//		}
//	});
//});

//function AddPageToAlbum(albumId) {
//  $.ajax(
//			{
//			  type: 'POST',
//			  url: '/MyAlbums/AddPageToAlbum',
//			  data: { albumId: albumId },
//			  dataType: "json",

//			  success: function (data, response) {


//			  }
//			});

//  return true;
//}


//function addStampToAlbum(albumId, stampId, pageNumber) {

//  $.ajax(
//			{
//			  type: 'POST',
//			  url: '/MyAlbums/AddStampToAlbum',
//			  data: { albumId: albumId, stampId: stampId, pageNumber: pageNumber },
//			  dataType: "json",

//				success: function (data, response) {
//			   

//			  }
//			});
//  
//};

//function removeStampFromAlbum(albumId, stampId) {

//  $.ajax(
//			{
//			  type: 'POST',
//			  url: '/MyAlbums/RemoveStampFromAlbum',
//			  data: { albumId: albumId, stampId: stampId },
//			  dataType: "json",

//			  success: function (data, response) {


//			  }
//			});

//};




////$(function () {
////	// there's the gallery and the trash
////	var $gallery = $("#gallery");
////	var $albumPage = $("#albumPage");



////	// let the gallery items be draggable
////	$("li", $gallery).draggable({
////		cancel: "a.ui-icon", // clicking an icon won't initiate dragging
////		revert: "invalid", // when not dropped, the item will revert back to its initial position
////		containment: $("#demo-frame").length ? "#demo-frame" : "document", // stick to demo-frame if present
////		helper: "clone",
////		cursor: "move"
////	});

////	$("li", $albumPage).draggable({
////		cancel: "a.ui-icon", // clicking an icon won't initiate dragging
////		revert: "invalid", // when not dropped, the item will revert back to its initial position
////		containment: $("#demo-frame").length ? "#demo-frame" : "document", // stick to demo-frame if present
////		helper: "clone",
////		cursor: "move"
////	});



////	// let the album be droppable, accepting the gallery items
////	$albumPage.droppable({

////		accept: "#gallery > li",
////		activeClass: "ui-state-highlight",
////		drop: function (event, ui) {
////			deleteImage(ui.draggable);

////			var stampId = ui.draggable.find("p").text();
////			var albumId = $('#AlbumId').text();
////			var selectedPage = $('#CurrentSelectedPage').val();
////			alert(selectedPage);
////			addStampToAlbum(albumId, stampId, selectedPage);
////			//alert(albumId);
////		}
////	});

////	// let the gallery be droppable as well, accepting items from the trash
////	$gallery.droppable({
////		accept: "#albumPage li",
////		activeClass: "custom-state-active",
////		drop: function (event, ui) {
////			recycleImage(ui.draggable);

////			var stampId = ui.draggable.find("p").text();
////			var albumId = $('#AlbumId').text();

////			removeStampFromAlbum(albumId, stampId);
////		}
////	});




////	// image deletion function
////	var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Recycle this image' class='ui-icon ui-icon-refresh'>Recycle image</a>";
////	function deleteImage($item) {
////		$item.fadeOut(function () {
////			var $list = $("ul", $albumPage).length ?
////					$("ul", $albumPage) :
////					$("<ul class='gallery ui-helper-reset'/>").appendTo($albumPage);

////			$item.find("a.ui-icon-trash").remove();
////			$item.append(recycle_icon).appendTo($list).fadeIn(function () {
////				$item
////						.animate({ width: "48px" })
////						.find("img")
////							.animate({ height: "36px" });
////			});
////		});
////	}

////	// image recycle function
////	var trash_icon = "<a href='link/to/trash/script/when/we/have/js/off' title='Delete this image' class='ui-icon ui-icon-trash'>Delete image</a>";
////	function recycleImage($item) {
////		$item.fadeOut(function () {
////			$item
////					.find("a.ui-icon-refresh")
////						.remove()
////					.end()
////					.css("width", "96px")
////					.append(trash_icon)
////					.find("img")
////						.css("height", "72px")
////					.end()
////					.appendTo($gallery)
////					.fadeIn();
////		});
////	}


////	// image preview function, demonstrating the ui.dialog used as a modal window
////	function viewLargerImage(dlgId, title) {
////		var jq = '#' + dlgId;
////		$(jq).dialog({ width: 400, title: title, modal: true });
////		return false;
////	}

////	// resolve the icons behavior with event delegation
////	$("ul.gallery > li").click(function (event) {
////		var $item = $(this),
////				$target = $(event.target);
////		var dlgId = $target.attr("dlgId");
////		var dlgTitle = $target.attr("title");

////		if ($target.is("a.ui-icon-trash")) {
////			deleteImage($item);
////		} else if ($target.is("a.ui-icon-zoomin")) {
////			viewLargerImage(dlgId, dlgTitle);
////		} else if ($target.is("a.ui-icon-refresh")) {
////			recycleImage($item);
////		}

////		return false;
////	});
////});
////	
